<template >
  <div>
    <el-table :data="getspect" border style="width: 100%">
      <el-table-column prop="id" label="规格编号">
      </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column prop="attrs" label="规格属性">
        <template slot-scope="item">
          <div>
            <p v-for="(attr, index) in item.row.attrs" :key="index">{{ attr }}</p>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? "开启" : "禁用" }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button class="btnInfo" @click="edit(item.row.id)" type="primary" size="mini" >编辑</el-button>
            <el-button class="btnInfo" @click="del(item.row.id)" type="danger" size="mini" >删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @current-change="changePage" background :page-size="getsize" layout="prev, pager, next"
      :total="getcount">
    </el-pagination>

  </div>
</template>
<script>
import { specsdelete } from '../../request/api'
import { mapActions, mapGetters } from 'vuex'
export default {
  data() {
    return {

    };
  },

  computed: {
    ...mapGetters({
      getspect: 'specs/getspecs', // 获取总数据
      getcount: 'specs/getcount', //获取总页数
      getsize: 'specs/getsize',   // 查询条数
    })
  },

  mounted() {
    this.getSpectAction()
    this.getCountAction()
    console.log(this.getspect);
  },

  methods: {
    ...mapActions({
      getSpectAction: 'specs/getSpectAction', // 获取总数据
      getCountAction: 'specs/getCountAction', // 获取总页数
      changePageAction: 'specs/changePageAction', // 重新触发列表的事件
    }),


    // 点击页码切换
    changePage(e) {
      this.changePageAction(e)
    },


    // 点击编辑
    edit(id) {
      // console.log(id);
      this.$emit('edit', id)
    },

    // 点击删除
    del(id) {
      // console.log(id);
      this.$confirm("你确定要删除这条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          specsdelete({ id }).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              //页面一加载就调用列表接口以及总条数
              this.getSpectAction();
              this.getCountAction();
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    }

  },
};
</script>
<style lang="">
</style>